import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:yp/helper.dart';
import 'package:get/get.dart';
import 'package:yp/router.dart';

import 'logic.dart';
import 'state.dart';

class FeedbackHistoryPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _FeedbackHistoryPage();
  }
}

class _FeedbackHistoryPage extends State<FeedbackHistoryPage> {
  final FeedbackHistoryLogic logic = Get.put(FeedbackHistoryLogic());
  final FeedbackHistoryState state = Get.find<FeedbackHistoryLogic>().state;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Color(0xfff3f4f6),
      appBar: AppBar(
        centerTitle: true,
        elevation: 0,
        backgroundColor: Colors.white,
        title: Text(
          '反馈历史',
          style: TextStyle(
            color: Color(0xff030303),
            fontSize: 18,
          ),
        ),
        iconTheme: IconThemeData(
          color: Color(0xff333333),
        ),
      ),
      body: GetBuilder<FeedbackHistoryLogic>(
        builder: (logic) {
          return Container(
            color: Color(0xffF3F4F6),
            child: Padding(
                padding: EdgeInsets.only(
                  top: setWidth(2),
                ),
                child: SmartRefresher(
                  controller: state.refreshCtrl,
                  enablePullDown: true,
                  enablePullUp: true,
                  onLoading: logic.onLoadding,
                  onRefresh: logic.onRefresh,
                  header: CustomHeader(
                    builder: (BuildContext context, RefreshStatus mode) {
                      Widget body;
                      if (mode == RefreshStatus.completed) {
                        body = CupertinoActivityIndicator();
                      }
                      return Container(
                        height: 55.0,
                        child: Center(child: body),
                      );
                    },
                  ),
                  child: ListView.separated(
                    scrollDirection: Axis.vertical,
                    // padding: EdgeInsets.symmetric(vertical: setWidth(20)),
                    itemBuilder: (context, index) {
                      return InkWell(
                        child: _itemWidget(index: index),
                        onTap: () {
                          Get.toNamed(RouteConfig.opinionFeedbackDetails,
                              arguments: state.dataList[index]);
                        },
                      );
                    },
                    separatorBuilder: (BuildContext context, int index) {
                      return SizedBox(
                        height: setWidth(20),
                      );
                    },
                    itemCount: state.dataList.length,
                  ),
                )),
          );
        },
      ),
      bottomNavigationBar: Container(
          height: setWidth(100),
          margin: EdgeInsets.symmetric(
              horizontal: setWidth(32),
              vertical: Get.bottomBarHeight + setWidth(60)),
          decoration: BoxDecoration(
              color: Colors.white,
              border:
                  Border.fromBorderSide(BorderSide(color: Color(0xffCCCCCC))),
              borderRadius: BorderRadius.circular(setWidth(50))),
          child: MaterialButton(
            onPressed: () {
              Get.back();
            },
            child: Text(
              '继续反馈',
              style:
                  TextStyle(fontSize: setWidth(36), color: Color(0xff666666)),
            ),
          )),
    );
  }

  // item
  Widget _itemWidget({
    int index,
  }) {
    //login
    Map _data = state.dataList[index];
    return Container(
      // height: setWidth(200),
      width: MediaQuery.of(context).size.width,
      color: Colors.white,

      padding: EdgeInsets.only(
        left: setWidth(30),
        top: setWidth(32),
        right: setWidth(20),
        bottom: setWidth(32),
      ),
      child: Row(
        children: [
          Expanded(
            child: Container(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Text(
                    '反馈类型：' + _data['group_name'],
                    maxLines: 1,
                    overflow: TextOverflow.ellipsis,
                    style: TextStyle(
                      color: Color(0xffDB2132),
                      fontSize: 14,
                    ),
                  ),
                  SizedBox(
                    height: setWidth(10),
                  ),
                  Text(
                    '反馈内容：' + _data['feedback_content'],
                    style: TextStyle(
                      color: Color(0xff222222),
                      fontSize: 14,
                    ),
                  ),
                  SizedBox(
                    height: setWidth(10),
                  ),
                  Text(
                    '反馈时间：' + _data['create_dtme'],
                    style: TextStyle(
                      color: Color(0xff999999),
                      fontSize: 12,
                    ),
                  ),
                ],
              ),
            ),
          ),
          SizedBox(
            width: setWidth(20),
          ),
          Image.asset(
            'assets/images/icon-left.png',
            width: setWidth(12),
            height: setWidth(20),
            color: Color(0xffcccccc),
            fit: BoxFit.cover,
          )
        ],
      ),
    );
  }

  // 继续反馈
  Widget _continueFeedbackWidget() {
    return Container(
      padding: EdgeInsets.symmetric(
        horizontal: setWidth(20),
        vertical: setWidth(50),
      ),
      child: Container(
        height: setWidth(90),
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.circular(setWidth(45)),
          border: Border.all(
            color: Color(0xffcccccc),
            width: setWidth(1),
          ),
        ),
        alignment: Alignment.center,
        child: Text(
          '继续反馈',
          style: TextStyle(
            color: Color(0xff666666),
            fontSize: 18,
          ),
        ),
      ),
    );
  }
}
